function qvImage(mode)
% qvImage

% gs feb 2008
% -------------------------
if nargin == 0
    mode = 'init';
end
currentdir = cd;
switch mode
    case 'init'
%         defaultDir = 'C:\_Data\bead labeling';
%         defaultDir = 'F:\FALSTAFF\DATA\Jianing';
        defaultDir = 'C:/DATA/Ben/cells/';
        try
            cd(defaultDir)
        catch
            try
                defaultDir = 'C:\_Data\bead labeling';
                cd(defaultDir)
            catch
            end
        end
        [filename, pathname] = uigetfile('*.*');
        if filename == 0 & pathname == 0
            return
        end

        % imtool([pathname filename])

        I = imread([pathname filename]);

        figure('Toolbar', 'figure');
        colormap gray;
        addMenu4DistanceMeasure;

        imagesc(I);
        daspect([1 1 1]);
        title(filename);

        % uicontrols for rotation
        uicontrol('Style', 'pushbutton', 'String', 'CW', 'Units', 'normalized', ...
            'Position', [.92 .93 .04 .07], 'Callback', 'qvImage(''CW'')');
        uicontrol('Style', 'pushbutton', 'String', 'CCW', 'Units', 'normalized', ...
            'Position', [.96 .93 .04 .07], 'Callback', 'qvImage(''CCW'')');

        % uicontrols for contrast

        % uicontrols for offset
        
        % store data
        data.I = I;
        data.angle = 0;
        data.filename = filename;
        set(gcf, 'UserData', data);
        
        cd(currentdir)
        
    case 'CW'
        rotImg(mode);
        return
        
    case 'CCW'
        rotImg(mode);
        return
end

% subroutines --------------------------------
function rotImg(mode)
data = get(gcf, 'UserData');
if strcmp(mode, 'CW')
    direction = 1;
elseif strcmp(mode, 'CCW')
    direction = -1;
end
increment = 2.5;
data.angle = data.angle + increment * direction;
I = imrotate(data.I, data.angle); 
set(gcf, 'UserData', data);

imagesc(I);
daspect([1 1 1]);
title(data.filename);

